import formDownload from '../../../../../../hrpub/common/utils/download/download';
import {
    gzip as GZip,
    toast,
    // formDownload
} from 'nc-lightapp-front';

const gzip = new GZip();

import language from '../../../language';

import unzip from '../../../../../../hrpub/common/utils/unZipAndDecrypt';

export default function exportPsnInfo() {
    const {editTable, orgVal, show_on_job_psn, exportAllpks, exportType} = this.props;
    const {queryMode, targetKeys} = this.state;
    let psnjobPks = '';
    if (exportType === 'all') {
        psnjobPks = exportAllpks.join();
    } else {
        const checkedRows = editTable.getCheckedRows('ncc60071701list');

        if (checkedRows.length === 0) {
            psnjobPks = editTable.getClickRowIndex('ncc60071701list').record.values.pk_psnjob.value;
        } else {
            psnjobPks = checkedRows.map(item => item.data.values.pk_psnjob.value).join();
        }

    }
    let postData = {
        pk_org: orgVal.refpk,
        func_type: 2,
        queryMode,
        show_on_job_psn,
        psnjobPks,
        infosetPKs: targetKeys.join()
    };

    // formDownload({
    //     params: postData,
    //     url: '/nccloud/hrhi/psndoc/PsndocExportPsninfoDoAction.do',
    //     enctype: 2
    // })


    return formDownload({
        body: postData,
        url: '/nccloud/hrhi/psndoc/PsndocExportPsninfoDoAction.do',
        enctype: 2,
        onResult: (body) => {
            let res = unzip(body.innerText);
            
            if(!res || res.success) {
                toast({
                    color: 'success',
                    content: language['hi6007-000185'] // 导出成功
                });
            }
            else {
                toast({
                    color: 'danger',
                    content: res.error.message // 导出成功
                });
            }
        },
        options: {
            appcode: this.props.appcode,
            target: '_blank'
        }
    });
}
